<?php

namespace Biblibase\UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class UserType extends AbstractType
{
        /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
    	  
        $builder
            ->add('username', 'text', array('attr' => array('placeholder' => 'Utilisateur'), 'label' => false))
            ->add('password', 'repeated', array(
    					'type' => 'password',
    					'invalid_message' => 'Les mots de passe doivent correspondre',
   				   'options' => array('required' => true),
    					'first_options'  => array('label' => false, 'attr' => array('placeholder' => 'Mot de passe')),
    					'second_options' => array('label' => false, 'attr' => array('placeholder' => 'Confirmez mot de passe'))))
            ->add('roles', 'choice', array(
  						'choices'    => array('ajout' => 'Ajout de contenu',
													 'ajoutU' => 'Ajout d\'utilisateur',
													 'modification' => 'Modification du contenu',
													 'suppression' => 'Suppression de contenu',
													 'suppressionU' => 'Suppression d\'utilisateur'											
  													),
  						 'multiple' => true,
      				 'expanded' => true,
      				 'label' => 'Droits',
      				 'label_attr' => array('class' => 'labelTitre'),
      				 'required' => false
  						));
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Biblibase\UserBundle\Entity\User'
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'biblibase_userbundle_user';
    }
}
